package com.everflourish.yeah100.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.everflourish.yeah100.R;
import com.everflourish.yeah100.entity.DrawerMenu;
import com.everflourish.yeah100.entity.DrawerMenuModel;

import java.util.List;

/**
 * 作者：Created by liqisi on 2016/6/6.
 * 时间：2016/6/6
 */
public class DrawerLeftAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private Context mContext;
    private List<DrawerMenuModel> mList;

    public DrawerLeftAdapter(Context mContext, List<DrawerMenuModel> mList) {
        this.mContext = mContext;
        this.mList = mList;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        DrawerMenu drawerList = mList.get(position).getDrawerMenu();
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_drawer_list,
                    parent, false);
            if (position == 0) {
                mList.get(position).setIsChoose(true);
            }
            viewHolder.mMenuIc = (ImageView) convertView.findViewById(R.id.drawer_list_iv);
            viewHolder.mMenuTv = (TextView) convertView.findViewById(R.id.drawer_list_tv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        boolean isChoose = mList.get(position).isChoose();
        viewHolder.mMenuIc.setImageResource(drawerList.getImageId());
        viewHolder.mMenuTv.setText(drawerList.getTextViewSt());
        if (isChoose) {
            convertView.setBackgroundColor(mContext.getResources().getColor(R.color.list_drawer_item_selector));
        } else {
            convertView.setBackgroundResource(R.drawable.selector_drawer_list);
        }
        return convertView;
    }

    public class ViewHolder {
        private ImageView mMenuIc;
        private TextView mMenuTv;
    }
}